/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package metro.jme.lottery.graphics.sprite;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 * This sprite is used to display an explosion at the end of the animation
 * when the used is checking his favourite set.
 * @author pierre
 */
public class ExplosionSprite extends Sprite {

	private int currentPosX;
	private int currentPosY;
	private static final String image = "/imgs/explosion.jpeg";
	private static final int FRAME_WIDTH = 45;
	private static final int FRAME_HEIGHT = 45;
	private static final int[] seq = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
									  11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
									  21, 22, 23, 24};
	public static final int SEQ_SIZE = 25;
	private int frame;

	private ExplosionSprite(Image img, int x, int y) {
		super(img, FRAME_WIDTH, FRAME_HEIGHT);
		currentPosX = x;
		currentPosY = y;
		setPosition(x, y);
		frame = 0;
		setFrameSequence(seq);
	}

	public static ExplosionSprite createSprite(int x, int y) {
		try {
			Image img = Image.createImage(image);
			return new ExplosionSprite(img, x, y);
		} catch (IOException ex) {
			ex.printStackTrace();
			return null;
		}
	}

	/**
	 * Method displaying a new frame of the animation
	 * @param g
	 * @return 
	 */
	public boolean next(Graphics g) {
		if (frame < SEQ_SIZE - 1) {
			nextFrame();
			paint(g);
			frame++;
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Method used to know if the animation should stop
	 * @return 
	 */
	public boolean done() {
		return frame == SEQ_SIZE - 1;
	}
}
